//
//  ViewController.m
//  MoviePlayer
//
//  Created by student on 16/4/5.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"
#import <MediaPlayer/MediaPlayer.h>
@interface ViewController ()

@property (nonatomic,strong) MPMoviePlayerViewController *moviePlayerVC;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


// 练习:
// 制作一个媒体文件列表页
// 1. 显示打包中的媒体文件(avi,mkv,mov,m4v,mp4,3gp)
// 2. 显示沙盒中的媒体文件(NSFileManager 遍历沙盒目录下的文件)
// 3. 点击列表中视频弹出播放器播放


- (IBAction)btnPressed:(id)sender
{
    NSURL *filerURL = [[NSBundle mainBundle] URLForResource:@"Movie" withExtension:@"m4v"];
    self.moviePlayerVC = [[MPMoviePlayerViewController alloc] initWithContentURL:filerURL];
    //1.弹出方式
//    self.moviePlayerVC.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
//    self.moviePlayerVC.moviePlayer.scalingMode = MPMovieScalingModeFill;
//    [self presentMoviePlayerViewControllerAnimated:self.moviePlayerVC];
//    [self.view addSubview:self.moviePlayerVC.view];
    
    
    // 监听播放器(播放完成)的通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playDone) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
    
    // 2. 嵌入当前页面
    self.moviePlayerVC.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
    self.moviePlayerVC.moviePlayer.scalingMode = MPMovieControlStyleNone;
    self.moviePlayerVC.view.frame = CGRectMake(0, 200, 350, 200);
    [self.view addSubview:self.moviePlayerVC.view];
    
    
    [self.moviePlayerVC.moviePlayer play];
}


- (void)playDone
{
    NSLog(@"播放完毕了,关闭播放器");
    
    [self dismissMoviePlayerViewControllerAnimated];
}

@end
